package com.monitoring.domain.valueobject;

import lombok.Value;
import java.time.LocalDateTime;

@Value
public class EnergyConsumption {
    private double value;
    private String unit; // kWh
    private LocalDateTime timestamp;
    private String deviceId;
    
    public EnergyConsumption(double value, LocalDateTime timestamp, String deviceId) {
        if (value < 0) {
            throw new IllegalArgumentException("Energy consumption cannot be negative");
        }
        this.value = value;
        this.unit = "kWh";
        this.timestamp = timestamp != null ? timestamp : LocalDateTime.now();
        this.deviceId = deviceId;
    }
    
    public boolean isHighConsumption() {
        return value > 10.0; // 假设超过10kWh为高能耗
    }
    
    public double getCost(double pricePerKwh) {
        if (pricePerKwh < 0) {
            throw new IllegalArgumentException("Price per kWh cannot be negative");
        }
        return Math.round(value * pricePerKwh * 100) / 100.0;
    }
}